package com.isoftstone.industry.aaa.core.service.accounting.charging.impl;

import java.sql.Timestamp;

import javax.annotation.Resource;

import com.isoftstone.industry.common.util.SNGenerator;
import com.isoftstone.industry.persistance.bean.AccountItemType;
import com.isoftstone.industry.persistance.bean.BillingCycle;
import com.isoftstone.industry.persistance.bean.BillingList;
import com.isoftstone.industry.persistance.bean.ChargingItemDetail;
import com.isoftstone.industry.persistance.bean.ProductInstance;
import com.isoftstone.industry.persistance.bean.TicketInfo;
import com.isoftstone.industry.persistance.bean.User;
import com.isoftstone.industry.aaa.core.log.BusinessLogger;
import com.isoftstone.industry.aaa.core.service.assist.IBillingListService;
import com.isoftstone.industry.aaa.core.service.assist.IChargingItemDetailService;
import com.isoftstone.industry.aaa.core.service.assist.IChargingItemService;
import com.isoftstone.industry.aaa.core.service.assist.IUserService;
import com.isoftstone.industry.aaa.utils.SystemProperties;
import com.isoftstone.modules.core.utils.DateUtils;

public class AbstractChargingEnginer
{
	protected User							user;

	protected BillingCycle					billingCycle;

	protected ChargingItemDetail			chargingItemDetail;

	@Resource
	protected BusinessLogger				logger;

	@Resource
	protected IChargingItemService			chargingItemService;

	@Resource
	protected IChargingItemDetailService	chargingItemDetailService;

	@Resource
	protected IUserService					userService;

	@Resource
	protected SystemProperties				systemProperties;

	@Resource
	protected IBillingListService			billingListService;

	public AbstractChargingEnginer()
	{
		super();
	}

	public AbstractChargingEnginer(User user, BillingCycle billingCycle, ChargingItemDetail chargingItemDetail)
	{
		super();
		this.user = user;
		this.billingCycle = billingCycle;
		this.chargingItemDetail = chargingItemDetail;
	}

	public User getUser()
	{
		return user;
	}

	public void setUser(User user)
	{
		this.user = user;
	}

	public BillingCycle getBillingCycle()
	{
		return billingCycle;
	}

	public void setBillingCycle(BillingCycle billingCycle)
	{
		this.billingCycle = billingCycle;
	}

	public ChargingItemDetail getChargingItemDetail()
	{
		return chargingItemDetail;
	}

	public void setChargingItemDetail(ChargingItemDetail chargingItemDetail)
	{
		this.chargingItemDetail = chargingItemDetail;
	}

	public void initialize(User user, BillingCycle billingCycle, ChargingItemDetail chargingItemDetail)
	{
		this.user = user;
		this.billingCycle = billingCycle;
		this.chargingItemDetail = chargingItemDetail;
	}

	protected BillingList createBillingList(User user, ChargingItemDetail detail, ProductInstance prodInst, AccountItemType acctItemType,
			String type, Double amount, String comments, TicketInfo ticketInfo, Timestamp start, Timestamp end)
	{
		BillingList billingList = new BillingList();
		billingList.setSn(SNGenerator.createBillingListSN());
		billingList.setAcctItemType(acctItemType);
		billingList.setChargingItemDetail(detail);
		billingList.setProductInstance(prodInst);
		billingList.setAmount(amount);
		billingList.setComments(comments);
		billingList.setType(type);
		billingList.setTicketInfo(ticketInfo);
		billingList.setUser(user);
		billingList.setStartTime(start);
		billingList.setEndTime(end);
		billingList.setCreatedTime(DateUtils.getCurrentTimestamp());
		return billingListService.save(billingList);
	}
}
